import 'package:flutter/material.dart';
import 'package:hospitable_rental/pages/home/home/home_advisory.dart';
import 'package:hospitable_rental/pages/home/profile/profile_advertisement.dart';
import 'package:hospitable_rental/pages/home/profile/profile_button.dart';
import 'package:hospitable_rental/pages/home/profile/profile_header.dart';
import 'package:hospitable_rental/routes/routes.dart';
import 'package:hospitable_rental/viewmodels/auth_viewmodel.dart';
import 'package:provider/provider.dart';

class MineIndex extends StatefulWidget {
  const MineIndex({Key? key}) : super(key: key);

  @override
  _MineIndexState createState() => _MineIndexState();
}

class _MineIndexState extends State<MineIndex> {
  void _onSettings() {
    Navigator.of(context).pushNamed(Routes.setting);
  }

  @override
  Widget build(BuildContext context) {
    var isLogin = context.watch<AuthViewModel>().isLogin;

    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        title: Text("我的"),
        actions: [
          IconButton(
            onPressed: isLogin ? _onSettings : null,
            icon: Icon(
              Icons.settings,
              color: isLogin ? Colors.white : Theme.of(context).primaryColor,
            ),
          )
        ],
      ),
      body: ListView(
        children: [
          ProfileHeader(),
          ProfileButton(),
          ProfileAdvertisement(),
          AdvisoryWidget(),
        ],
      ),
    );
  }
}
